package com.xxx.video.mine.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.CountUtils;
import com.xxx.video.commen.utils.DimensionUtil;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.mine.beans.DynamicListBean;

import butterknife.BindView;

public class VideoManagementListAdapter extends BaseRecycleViewAdapter<DynamicListBean.PageBean.ListBean, VideoManagementListAdapter.MyHolder> {


    public VideoManagementListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_video_management_list;
    }


    class MyHolder extends BaseViewHolder {

        @BindView(R.id.iv_item_video_management_cover)
        ImageView ivItemVideoManagementCover;
        @BindView(R.id.tv_item_video_management_cover_play_count)
        TextView tvItemVideoManagementCoverPlayCount;
        @BindView(R.id.tv_item_video_management_cover_comment_count)
        TextView tvItemVideoManagementCoverCommentCount;
        @BindView(R.id.tv_item_video_management_title)
        TextView tvItemVideoManagementTitle;
        @BindView(R.id.tv_item_video_management_time)
        TextView tvItemVideoManagementTime;
        @BindView(R.id.iv_item_video_management_delete)
        ImageView ivItemVideoManagementDelete;
        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            DynamicListBean.PageBean.ListBean listBean = getItem(position);
            /*
             * title
             */
            tvItemVideoManagementTitle.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fTitle));
            /*
             * cover
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.fPicurl))
                    .apply(new RequestOptions()
                            .error(R.drawable.bg_place_holder_nine_five)
                            .placeholder(R.drawable.bg_place_holder_nine_five)
                            .transform(new CenterCrop(), new RoundedCorners(DimensionUtil.dpToPx(5))))
                    .into(ivItemVideoManagementCover);
            /*
             * play count
             */
            tvItemVideoManagementCoverPlayCount.setText(CountUtils.getInstance().getCount(listBean.fPlayTimes));
            /*
             *comment count
             */
            tvItemVideoManagementCoverCommentCount.setText(CountUtils.getInstance().getCount(listBean.fCommentTimes));
            /*
             * time
             */
            tvItemVideoManagementTime.setText(StringUtils.getInstance().getNotEmptyMsg(String.valueOf(listBean.fCreateTime)));
            ivItemVideoManagementDelete.setOnClickListener(v -> {
                if (onItemClickListener!=null){
                    onItemClickListener.onItemClick(listBean,position,1);
                }
            });
        }
    }
}
